package com.example.presentshopping.utils.tool;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class UserInforBean {
    public static String getHtml(String path) throws Exception{
        //将path包装成一个URL对象
        URL url=new URL(path);
        //取得链接对象(基于HTTP协议链接对象)
        HttpURLConnection conn=(HttpURLConnection) url.openConnection();
        //设置超时时间
        conn.setConnectTimeout(5000);
        //设置请求方式
        conn.setRequestMethod("GET");
        //判断请求是否成功(看一下getResponseCode)
        if(conn.getResponseCode()==200){
            InputStream instream=conn.getInputStream();
            //流的工具类，专门从流中读取数据(返回的是二进制数据)
            byte[] data=StreamTool.read(instream);
            String html= new String(data,"UTF-8");
            return html;

        }
        return null;
    }

}
